<?php

namespace app\admin\controller;

use app\BaseController;


class AdminBase extends BaseController {

    public $token='';
    public $adminId=0;
    public $adminRoleId=0;
    public $adminAreaId=0;
    //public $departmentId=0;
    public function initialize(){
        parent::initialize();
        $this->token=$this->request->header('Authori-zation');

        if (!$this->token || !$this->isLogin()) {
            return $this->show(config("status.not_login"), "没有登录");
        }
        //$this->adminId=cache(config("redis.admin_token_pre") . $this->token) ? cache(config("redis.admin_token_pre") . $this->token)['id'] : 0;
        //$this->departmentId=cache(config("redis.admin_token_pre") . $this->token) ? cache(config("redis.admin_token_pre") . $this->token)['department_id'] : 0;
    }

    /**
     * 判断管理员是否登录
     * @return bool
     */
    public function isLogin()
    {
        $adminInfo = cache(config("redis.admin_token_pre") . $this->token);
        if (!$adminInfo) {
            return false;
        }

        if (!empty($adminInfo['id']) && !empty($adminInfo['username']) && !empty($adminInfo['roles'])) {
            $this->adminId = $adminInfo['id'];
            $this->adminRoleId = $adminInfo['roles'];
            $this->adminAreaId = $adminInfo['area_id'];
            return true;
        }
        return false;
    }

}
